package com.cy.personer.biz.impl;

import com.cy.personer.bean.MoneyDetails;
import com.cy.personer.bean.RoleUserOptions;
import com.cy.personer.bean.User;
import com.cy.personer.biz.OperationUserBiz;
import com.cy.personer.ceptor.OperationLog;
import com.cy.personer.mapper.MoneyDetailsMapper;
import com.cy.personer.mapper.OperationUserMapper;
import com.cy.personer.mapper.UserMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class OperationUserBizImpl implements OperationUserBiz {
    @Resource
    private OperationUserMapper operationUserMapper;
    @Resource
    private MoneyDetailsMapper moneyDetailsMapper;
    @Resource
    private UserMapper userMapper;

    //查询客户
    @Override
    public User getUser(String cardNumber) {
        return operationUserMapper.getUser(cardNumber);
    }

    //根据不同的角色ID获取不同的操作菜单
    @Override
    public List<RoleUserOptions> getRoleUserOptions(int roleId) {
        return operationUserMapper.getRoleUserOptions(roleId);
    }

    //为客户充值
    @Override
    public int recharge(User user,MoneyDetails moneyDetails) {
        int result = 0;
        boolean result1 = moneyDetailsMapper.addMoneyDetails(moneyDetails);
        boolean result2 = operationUserMapper.recharge(user);
        if(result1 && result2){
            result = 1;
        }else{
            result = 0;
        }
        return result;
    }

    //根据用户ID查询资金明细记录
    @Override
    public List<MoneyDetails> getMoneyDetails(MoneyDetails moneyDetails) {
        return moneyDetailsMapper.getMoneyDetails(moneyDetails);
    }

    //更新用户资金
    @Override
    public int updataUserMoney(User user, MoneyDetails moneyDetails) {
        int result = 0;
        boolean result1 = moneyDetailsMapper.addMoneyDetails(moneyDetails);
        boolean result2 = userMapper.updataUserMoney(user);
        if(result1 && result2){
            result = 1;
        }else{
            result = 0;
        }
        return result;
    }

}
